<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use app\admin\model\Admin;
use app\admin\model\Comment;
use think\Request;

class  Comments extends Base
{

    public function varlist(){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
            "list" => Comment::order("sort asc")->select(),
        );
        return view("varlist",$data);
    }

    //添加
    public function addform(){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
        );
        return view("addform",$data);
    }
    public function add(Request $request){
        $data = $request->post();
        $data['create_time'] = time();
        $data['update_time'] = time();
        if(Comment::insert($data)){
            $this->success("添加说明成功","Comments/varlist");
        }else{
            $this->error("添加说明失败","Comments/addform");
        }

    }
    //编辑
    public function update(Request $request){
        $user = $this->user_info();

        $data = array(
            "setting" => $this->getAllSetting(),
            "data" => Comment::where(array('id'=>$request->get('id')))->find(),
        );
        return view("update",$data);
    }
    public function edit(Request $request){
        $data = $request->post();
        $data['update_time'] = time();
        if(Comment::update($data)){
            $this->success("更新说明成功","Comments/varlist");
        }else{
            $this->error("更新说明失败","Comments/update");
        }

    }
    //删除
    public function delete(Request $request){
        $user = $this->user_info();
        if(Comment::destroy($request->post('id'))){
            $this->success("删除说明成功","Comments/varlist");
        }else{
            $this->error("删除说明失败","Comments/varlist");
        }
    }




}
